package com.example.shop.common.controller;
import com.example.shop.common.api.ResponseResult;
import com.example.shop.common.api.ServiceStateCode;
import com.example.shop.common.service.BriefInfoService;
import com.example.shop.merchant.dto.MerchantBriefInfo;
import com.example.shop.user.dto.UserBriefInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/common/avatar")
public class BriefInfoController {

    @Autowired
    BriefInfoService briefInfoService;

    @GetMapping(value = "/merchant/{merchantId}",consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseResult<MerchantBriefInfo> getMerchantBriefInfo(@PathVariable("merchantId") long merchantId){
        MerchantBriefInfo merchantAvatar = briefInfoService.getMerchantAvatar(merchantId);
        if(merchantAvatar==null){
            return ResponseResult.failure(ServiceStateCode.NO_EXIST_MERCHANT);
        }
        return ResponseResult.success(merchantAvatar);
    }

    @GetMapping(value = "/user/{userId}",consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseResult<UserBriefInfo> getUserBriefInfo(@PathVariable("userId")long userId){
        UserBriefInfo userAvatar = briefInfoService.getUserAvatar(userId);
        if(userAvatar==null){
            return ResponseResult.failure(ServiceStateCode.NO_EXIST_USER);
        }
        return ResponseResult.success(userAvatar);
    }
}
